package com.software.levelupandroid.taskIssue.presenter;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.software.levelupandroid.entity.Task;
import com.software.levelupandroid.service.NotionService;
import com.software.levelupandroid.taskIssue.CallBack;
import com.software.levelupandroid.taskIssue.model.IModel;
import com.software.levelupandroid.taskIssue.model.TaskIssueModel;
import com.software.levelupandroid.taskIssue.view.IView;

/**
 * @Description 任务发布的Presenter
 * @Author LiangYaJie
 * @CreateTime 2024年05月15日 09:12:57
 */
public class TaskIssuePresenter implements IPresenter, CallBack {
    private IView taskIssueView;
    private IModel taskIssueModel;

    public TaskIssuePresenter(IView taskIssueView) {
        this.taskIssueView = taskIssueView;
        taskIssueModel = new TaskIssueModel();
    }

    @Override
    public void issueTask(Task task, Context context) {
        taskIssueModel.issueTask(task, context, this);
    }

    @Override
    public void updateTask(Task task, Context context) {
        taskIssueModel.updateTask(task, context, this);
    }

    public void isFinishTask(Task task, Context context){
        taskIssueModel.updateTask(task, context, new CallBack() {
            @Override
            public void onSuccess(Task task) {
                taskIssueView.isFinishSuccess(task);
            }

            @Override
            public void onFailure(String msg) {
                taskIssueView.isFinishFailure(msg);
            }
        });
    }

    @Override
    public void deleteTask(Task task, Context context) {
        taskIssueModel.deleteTask(task, context, new CallBack() {
            @Override
            public void onSuccess(Task task) {
                taskIssueView.deleteTaskSuccess(task);
            }

            @Override
            public void onFailure(String msg) {
                taskIssueView.deleteTaskFailure(msg);
            }
        });
    }

    @Override
    public void updateExperience(double experience, Context context){
        taskIssueModel.updateExperience(experience, context, new com.software.levelupandroid.home.CallBack() {
            @Override
            public void onSuccess(Object data) {
                String str = (String) data;
                taskIssueView.updateExperienceSuccess(str);
            }

            @Override
            public void onFailure(String msg) {
                taskIssueView.updateExperienceFailure(msg);
            }
        });
    }

    @Override
    public void onSuccess(Task task) {
        taskIssueView.issueTaskSuccess(task);
    }

    @Override
    public void onFailure(String msg) {
        taskIssueView.issueTaskFailure(msg);
    }
}
